<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width"/>
<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
<title>Hello APP</title>
<link rel="stylesheet" type="text/css" href="../../css/aui-flex.css" />
<link rel="stylesheet" type="text/css" href="../../css/aui.css" />
<link rel="stylesheet" type="text/css" href="../../css/common.css" />
<style>
.aui-content{
	padding: 1rem;
}
.tit{
	font-size: 1.2rem;
	font-weight: bold;
}
.block{
	width: 0.3rem;
	height: 0.3rem;
	display: inline-block;
	background-color: #363335;
	margin-right: 0.2rem;
}
.pt-36{
	padding-top: 1.8rem;
}
.info-list{
	font-size: 0.7rem;
}
dl.comFlexItem dt {
		width: 5rem;
}
dl.comFlexItem{
	padding-top: 0.25rem;
}
select,
input.textInput {
		font-size: 0.7rem;
		height: 2rem;
}
.comFlexItem select,
.comFlexItem input.textInput {
		text-align: right;
		padding: 0 0.5rem;
}
.bom-tit{
	padding-top: 1.1rem;
	font-size: 0.6rem;
	color: #999999;
}
.comBox{
	position: fixed;
	bottom: 1rem;
	border-radius: 5rem;
	padding: 0 1rem;
	width: 100%;
}
.comBtmBtn{
	height: 2.5rem;
	line-height: 2.5rem;
	border-radius: 5rem;
}
.getCode {
		width: 5.5rem;
		height: 2rem;
		line-height: 2rem;
		font-size: 0.6rem;
		color: #fff;
		background: #FF8A9C;
		border-radius: 0.2rem;
		text-align: center;
}
</style>
</head>
<body>
	<div class="aui-content" id="zhuan">
		<div class="tit color-000">转账</div>

		<div class="info-list">
			<dl class="comFlexItem aui-border-b">
				<dt>转账金额</dt>
				<dd class="flex-auto"><input type="text" id="money" name="" value="" placeholder="请输入转账金额" class="textInput"></dd>
			</dl>
			<dl class="comFlexItem aui-border-b">
				<dt>对方ID</dt>
				<dd class="flex-auto"><input type="text" id="friendid" name="" value="" placeholder="请输入对方ID" class="textInput"></dd>
			</dl>
		</div>
		<div class="infoItem aui-border-b aui-flex-col aui-flex-middle aui-flex-between">
				<div class="relative flex-auto">
						<input type="tel" maxLength="6" name="" value="" placeholder="输入验证码" class="textInput inp" id="code" >
						<div class="inputDel aui-hide" tapmode onclick="quxiao(this)"></div>
				</div>
				<div class="getCode ready" tapmode onclick="getCode()">获取验证码</div>
		</div>
	</div>

	<div class="comBox">
		<div class="comBtmBtn" tapmode onclick="save()">确定</div>
	</div>
</body>
<script type="text/javascript" src="../../script/import.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript">
var userId;
var userInfo;
// console.log(userInfo.user_mobile);
// userId = getUserId();
apiready = function(){
	api.parseTapmode();
	userId = getUserId();
	userInfo = getUserinfo();
console.log(userInfo.user_mobile);
}
function save(){
	var money =$$('#money').val();
	var friendid = $$('#friendid').val();
	if(money==''){
		toast('请填写转账金额')
		return
	}
	if(friendid==''){
		toast('请填写对方ID')
		return
	}
	//检查验证码是否正确
	var code = $$('#code').val()
	if(code == ''){
		toast('请输入验证码')
		return
	}
	api.ajax({
	    url: BASE_URL+'App/User/checkSmsCode',
	    method: 'post',
	    data: {
	        values: {
	            code: code,
							mobile: userInfo.user_mobile
	        },
	    }
	},function(ret, err){
	    if (ret.code == 1) {
				var postData = {};
				postData.money = money;
				postData.friendid = friendid;
				postData.userid = getUserId();
				console.log(JSON.stringify(postData))
				api.ajax({
						url: BASE_URL + 'App/Select/zhuanzhang',
						method: 'post',
						data: {
								values: postData
						}
				},function(ret, err){
					console.log(JSON.stringify(ret))
					reLogin()
					toast(ret.info)
								if (ret && ret.code == 1) {
										toast(ret.info);
										api.sendEvent({
												name: 'guanEvent'
										});
										setTimeout(function(){
											api.closeWin()
										},2000)
								}
						});
	    } else {
				toast('你输入的验证码有误')
	        // alert( JSON.stringify( err ) );
	    }
	});


		}

function getCode() {
		if (!$$('.getCode').hasClass('ready')) {
				return;
		}
		$$('.getCode').removeClass('ready');
		//发送验证码 接口地址
		smsUrl = 'App/User/sendSms';
		// testSmsUrl = 'App/User/addCode';
		//正式发短信接口
		api.ajax({
			url: BASE_URL + smsUrl,
			method: 'post',
			data: {
				values: {
					mobile: userInfo.user_mobile
				}
			}
		},function(ret, err){
			if (ret) {
				if(ret.Code=='OK'){
					toast('发送成功');
					times = 59;
					isinerval = setInterval("countDown()", 1000);
				}else{
					toast(ret.Message);
					$$('.getCode').addClass('ready');
				}
			}else{
				toast('发送失败，请稍候再试');
				$$('.getCode').addClass('ready');
			}
		});


}

function countDown() {
		if (times < 1) {
				$$('.getCode').addClass('ready').text('重新获取');
				clearInterval(isinerval);
				return;
		}
		$$('.getCode').text(times+'s');
		times--;
}


// }
</script>
</html>
